# take_photos.py

#-------------------- USER START ------------------------
window = (230, 230)
x  = 36
y  = 102
w  = 30
h  = 30
#--------------------  USER END  ------------------------

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing(window)
sensor.skip_frames(time = 2000)

img = sensor.snapshot()


img.save("template.pgm", (x, y, w, h))
print("saved template")

template = image.Image("template.pgm")

while(True):
    img = sensor.snapshot()
    roi = img.find_template(template, 0.7)
    if(roi == None):
        img.draw_string(0, 0, "not found", color = (0))
    else:
        img.draw_rectangle(roi[0], roi[1], roi[2], roi[3], color = (0))
        img.draw_cross(int(roi[0] + roi[2] / 2), int(roi[1] + roi[3] / 2), color = (0))
